- search_parameter_value_id = discerner_nested_record_id(f, :search_parameter_value)
- if f.object.disabled? && f.object.warnings.any?
  %tr.error
    %td
    %td.warnings{colspan: "6"}
      %span
        = f.object.warnings.full_messages.join(', ')

%tr{ id: "#{search_parameter_value_id}", class: "search_parameter_value fields #{'error' if f.object.warnings.any?} search_parameter_value_new" }
  %td.parameter_values_boolean_operator
    = f.hidden_field :display_order
    %span

  - if f.object.new_record? # this part is used for rendering newly added parameter values
    %td.operator
      = f.select(:operator_id, operator_options, { include_blank: true })
    %td.chosen
      = f.check_box :chosen
    %td.parameter_value
      = f.hidden_field :parameter_value_id, class: 'parameter_value_id'
      %span{ class: 'parameter_value_text' }
    %td.value
      = f.text_field :value
    %td.additional_value
      = f.text_field :additional_value
    %td.remove
      = discerner_link_to_remove_fields 'Remove', f, :search_parameter_values

  - else # this part is used for rendering existing parameter values
    - parameter = f.object.search_parameter.parameter
    - type      = parameter.parameter_type.name

    - case type
    - when 'list'
      %td.chosen
        = f.check_box :chosen
      %td.parameter_value
        = f.hidden_field :parameter_value_id, class: 'parameter_value_id'
        %span{ class: 'parameter_value_text' }
          = f.object.parameter_value.name
      %td{class: "remove", class: "invisible"}
        = discerner_link_to_remove_fields 'Remove', f, :search_parameter_values

    - when 'combobox'
      %td.parameter_value
        = render partial: 'discerner/parameters/values_autocompleter', locals: {parameter: parameter, f: f, search_parameter_value_id: search_parameter_value_id}
      %td.remove
        = discerner_link_to_remove_fields 'Remove', f, :search_parameter_values

    - when 'exclusive_list'
      %td.parameter_value
        - parameter.parameter_values.each do |parameter_value|
          .parameter_value_item
            = f.radio_button :parameter_value_id, parameter_value.id, class: 'parameter_value_id'
            = f.label :parameter_value_id, parameter_value.name
      %td{class: "remove", class: "invisible"}
        = discerner_link_to_remove_fields 'Remove', f, :search_parameter_values
    - else
      %td.operator
        - selected = f.object.operator.blank? ? nil : f.object.operator.id
        = f.select(:operator_id, options_for_select([["", ""]] + operator_options(type), selected))

      %td{class: "value #{'invisible' if f.object.operator && f.object.operator.operator_type == 'presence'}"}
        = f.text_field :value, class: "#{type == 'date' ? 'datepicker' : nil}"

      %td{class: "additional_value #{'invisible' unless f.object.operator && f.object.operator.operator_type == 'range'}"}
        = f.text_field :additional_value, class: "#{type == 'date' ? 'datepicker' : nil}"
      %td.remove
        = discerner_link_to_remove_fields 'Remove', f, :search_parameter_values

